<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>计算器</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/plugs/layui-v2.5.6/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<blockquote class="layui-elem-quote layui-text">
    回本计算器
</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>请输入</legend>
</fieldset>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-block">开始时间</label>
        <input type="text" name="start_time" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off"
               class="layui-input">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-block">矿机类型</label>
        <select name="cate_id" lay-filter="aihao" lay-verify="required">
            <option value=""></option>
            {foreach $list as $key => $val}
            <option value="{$val['id']}">{$val['title']}</option>
            {/foreach}
        </select>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-block">投入成本(CNY)</label>
        <input type="number" name="cost" lay-verify="required|number" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-block">电费(CNY/度)</label>
        <input type="number" name="electric" lay-verify="required|number" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-block">功率(瓦)</label>
        <input type="number" name="power" lay-verify="required|number" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-block">投入总算力(T)</label>
        <input type="number" name="number" lay-verify="required|number" autocomplete="off" class="layui-input">
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="__STATIC__/plugs/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/plugs/layui-v2.5.6/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(demo1)', function (data) {

            $.post("{:url('user/current_cycle')}", data.field, function (result) {
                console.log(result)
                if (result.code === 1) {
                    layer.alert(JSON.stringify(result.data), {
                        title: '预计回本时间'
                    })
                } else {
                    layer.msg(result.msg);
                }
            });
            return false;
        });

        //表单赋值
        layui.$('#LAY-component-form-setval').on('click', function () {
            form.val('example', {
                "username": "贤心" // "name": "value"
                , "password": "123456"
                , "interest": 1
                , "like[write]": true //复选框选中状态
                , "close": true //开关状态
                , "sex": "女"
                , "desc": "我爱 layui"
            });
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>

</body>
</html>